<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<button>点击</button>
<p></p>
<script>
    /**
     *  window对象给我们提供了一个location属性用来获取或设置窗体的URL, 并且可以用于解析URL
     * @type {HTMLButtonElement}
     */

    var btn = document.querySelector('button');
    var p = document.querySelector('p');
    var count = 5;


    btn.addEventListener('click', function () {
        console.log(location.href);
        location.href = 'https://www.baidu.com';
    })

    function jumpBaidu() {
        return function () {
            if (count > 0) {
                p.innerHTML = `${count}s之后跳转到百度页面`;
                count--;
            } else {
                location.href = 'https://www.baidu.com';
                clearInterval(timer);
                count = 5;
            }
        };
    }

    jumpBaidu();
    var timer = setInterval(jumpBaidu(), 1000);
</script>
</body>

</html>
